package com.ruoyi.web.controller.swimming;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.swimming.domian.MallCategory;
import com.ruoyi.swimming.service.IMallCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商城类目Controller
 * 
 * @author ruoyi
 * @date 2021-07-17
 */
@RestController
@RequestMapping("/system/category")
public class MallCategoryController extends BaseController
{
    @Autowired
    private IMallCategoryService mallCategoryService;

    /**
     * 查询商城类目列表
     */
    @PreAuthorize("@ss.hasPermi('system:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallCategory mallCategory)
    {
        startPage();
        List<MallCategory> list = mallCategoryService.selectMallCategoryList(mallCategory);
        return getDataTable(list);
    }

    /**
     * 导出商城类目列表
     */
    @PreAuthorize("@ss.hasPermi('system:category:export')")
    @Log(title = "商城类目", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallCategory mallCategory)
    {
        List<MallCategory> list = mallCategoryService.selectMallCategoryList(mallCategory);
        ExcelUtil<MallCategory> util = new ExcelUtil<MallCategory>(MallCategory.class);
        return util.exportExcel(list, "商城类目数据");
    }

    /**
     * 获取商城类目详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mallCategoryService.selectMallCategoryById(id));
    }

    /**
     * 新增商城类目
     */
    @PreAuthorize("@ss.hasPermi('system:category:add')")
    @Log(title = "商城类目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallCategory mallCategory)
    {
        return toAjax(mallCategoryService.insertMallCategory(mallCategory));
    }

    /**
     * 修改商城类目
     */
    @PreAuthorize("@ss.hasPermi('system:category:edit')")
    @Log(title = "商城类目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallCategory mallCategory)
    {
        return toAjax(mallCategoryService.updateMallCategory(mallCategory));
    }

    /**
     * 删除商城类目
     */
    @PreAuthorize("@ss.hasPermi('system:category:remove')")
    @Log(title = "商城类目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mallCategoryService.deleteMallCategoryByIds(ids));
    }
}
